import { PartialType } from '@nestjs/mapped-types';
import { Transform, Type } from 'class-transformer';
import { IsArray, IsBoolean, IsEnum, IsNumber, IsOptional, IsString } from 'class-validator';
import { SortOrderEnum, StatusEnum } from '@/common/enums';

export class CreateDictDto {
  @IsString()
  name: string;

  @IsString()
  @IsOptional()
  label?: string;

  @IsNumber()
  @IsOptional()
  sort?: number;

  @IsString()
  @IsOptional()
  description?: string;

  @IsString()
  @IsOptional()
  remark?: string;

  @IsEnum(StatusEnum)
  @IsOptional()
  status?: StatusEnum;
}

export class FindDictDto extends PartialType(CreateDictDto) {
  @IsNumber()
  @IsOptional()
  id?: number;

  @IsString()
  @IsOptional()
  sortField?: string = 'sort';

  @IsEnum(SortOrderEnum) // 确保 sortOrder 只能是 'ASC'升序 或 'DESC'降序
  @Transform(({ value }) => value.toUpperCase()) // 将输入转换为大写
  @IsOptional()
  sortOrder?: SortOrderEnum = SortOrderEnum.ASC; // 默认值按 sort 字段升序

  @IsNumber()
  @IsOptional()
  pageNum?: number = 1;

  @IsNumber()
  @IsOptional()
  pageSize?: number = 20;
}

export class UpdateDictDto extends PartialType(CreateDictDto) {
  @IsNumber()
  id: number;
}

export class RemoveDictDto extends PartialType(CreateDictDto) {
  @IsNumber()
  id: number;
}

export class CreateBatchDictDto {
  @IsArray()
  @Type(() => CreateDictDto)
  list: CreateDictDto[];

  @IsBoolean()
  @IsOptional()
  cover?: boolean = false;
}

export class RemoveBatchDictDto {
  @IsArray()
  ids: number[];
}
